package com.bluegalaxy.nhb.snservice.service.syn.impl;

import com.bluegalaxy.nhb.snservice.dao.UsersMapper;
import com.bluegalaxy.nhb.snservice.dao.SynMapper;
import com.bluegalaxy.nhb.snservice.domain.vo.api.R;
import com.bluegalaxy.nhb.snservice.service.execute.ExecuteService;
import com.bluegalaxy.nhb.snservice.service.execute.XxService;
import com.bluegalaxy.nhb.snservice.service.syn.SynService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * @author:
 * @date: 2021/6/23 12:59
 * @description:
 */

@Service("SynService")
public class SynServiceImpl implements SynService {

    private static Log log = LogFactory.getLog(SynServiceImpl.class);



    @Autowired
    private ExecuteService executeService;

    @Autowired
    private SynMapper synMapper;

    @Autowired
    private XxService xxService;

    @Autowired
    private UsersMapper usersMapper;

    @Override
    public R synUsers(){

        int length = 1000;
        List<Map<String,Object>> userList = xxService.selectUsers();
        if (!userList.isEmpty()){
            log.info("size:"+userList.size());
            int size = userList.size();
            int count = size % length != 0 ? size / length + 1 : size / length;
            for (int i = 0; i < count; i++) {
                log.info("i:"+i);
                List<Map<String,Object>> subList = userList.subList(i * length, ((length + i * length) < size ? (length + i * length) : size));
                if (subList.size() > 0){
                    usersMapper.insertBatch(subList);
                }
            }

        }

        return R.status(true);
    }

}
